package com.neudu.glsb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neudu.glsb.mapper.EmployeesMapper;
import com.neudu.glsb.pojo.Employees;
import com.neudu.glsb.service.EmployeesService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EmployeesServiceImpl extends ServiceImpl<EmployeesMapper, Employees> implements EmployeesService {
    @Override
    public Employees getEmployeeByAdminUserId(Integer adminUserId) {
        QueryWrapper<Employees> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("admin_user_id", adminUserId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public Employees getEmployeeInfoById(Integer id) {
        LambdaQueryWrapper<Employees> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Employees::getId, id);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<Employees> getUnassignedEmployees() {
        LambdaQueryWrapper<Employees> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.isNull(Employees::getAdminUserId);
        queryWrapper.orderByAsc(Employees::getId);
        return this.list(queryWrapper);
    }

    @Override
    public long countUnassignedEmployees() {
        LambdaQueryWrapper<Employees> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.isNull(Employees::getAdminUserId);
        return this.count(queryWrapper);
    }
}
